package no19.enum1;

import java.util.Random;

/**
 *利用泛型, 随机选取Enum元素
 * 
 * @author gao
 * 
 */

enum Test {
	A, B, C
}

public class Enums {
	private final static Random rand = new Random();
	
	public static <T extends Enum<T>> T random(Class<T> ec) {
		return random(ec.getEnumConstants());
	}

	public static <T> T random(T[] values) {
		return values[rand.nextInt(values.length)];
	}
}
